package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.InspectionRuleStatus;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "neuiot_inspection_rule")
@org.hibernate.annotations.Table(appliesTo = "neuiot_inspection_rule", comment = "巡检规则表")
public class InspectionRule extends AbstractAuditModel {

    private static final long serialVersionUID = 1L;

    @NotBlank(message = "部门编号")
    @Length(max = 255, message = "部门编号不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '部门编号'")
    private String orgCode;

    @Length(max = 255, message = "部门名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '部门名称'")
    private String orgName;

    @Length(max = 255, message = "规则名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '规则名称'")
    private String name;

    @Length(max = 255, message = "规则编号不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '规则编号'")
    private String code;

    @Enumerated(EnumType.STRING)
    @Column(length = 5, nullable = false)
    @Comment("varchar(5) NOT NULL COMMENT '规则状态'")
    private InspectionRuleStatus status = InspectionRuleStatus.start;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '起始时间'")
    private Date startDateTime;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '结束时间'")
    private Date endDateTime;

    @NotBlank(message = "创建人编码")
    @Length(max = 255, message = "创建人编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '创建人编码'")
    private String userCode;

    @Length(max = 255, message = "创建人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '创建人名称'")
    private String userName;

    @Length(max = 32, message = "巡检类型不能超过{max}位")
    @Column(length = 32, nullable = true)
    @Comment("varchar(32) NULL COMMENT '巡检类型：暖通、电气、高压'")
    private String inspectionType;

    @Column(length = 32, nullable = true)
    @Comment("int(32) NULL COMMENT '版本号'")
    private Integer version;

    @Length(max = 255, message = "cron表达式不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT 'cron表达式'")
    private String cronTime;

    @Column(length = 32, nullable = false)
    @Comment("varchar(32) NOT NULL COMMENT '持续时长'")
    private Integer duration;

    @Column(length = 1, nullable = false)
    @Comment("int(1) NOT NULL COMMENT '是否删除'")
    private Integer delFlag = 0;

    @OneToMany(mappedBy = "inspectionRule", cascade = CascadeType.ALL)
    List<InspectionRuleProject> inspectionProject = new ArrayList<>();

    @OneToMany(mappedBy = "inspectionRule")
    private List<InspectionTask> InspectionTask;
}
